#ifndef KVSTORE_H
#define KVSTORE_H
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

#ifdef _WIN32
//#include <windows.h>
#include "completePort/completePort.h"
#endif

#include "netReactor/reactor.h"
#include "io_uring/uring_tcp_server.h"
#include "coroutine/coroutineC.h"
#include "coroutine/coroutineSchdule.h"

#include "RBTree/RBTree.h"
#include "skiplist/skiplist.h"
#include "hash/hash.h"


#define PRINTFCMODE

#define USAGEREACTOR 		1			//使用reactor作为网络服务
#define USAGEIOURING 		0			//使用iouring作为网络服务
#define USAGECOROUTINE 		0			//使用coroutine作为网络服务
#define USAGEIOCP 			0			//使用IOCP(完成端口-windows平台)作为网络服务

#define ARRAYENGINEENABLE  		0	//使用数组作为存储引擎
#define RBTREEENGINEENABLE 		1	//使用红黑树作为存储引擎
#define SKIPLISTENGINEENABLE 	0	//使用跳表作为存储引擎
#define HASHENGINEENABLE 		0	//使用哈希表作为存储引擎

#define KVS_MAX_TOKEN 128

#define KVS_ARRAY_SIZE		1024
 
typedef struct kvs_array_item_s {
	char *key;
	char *value;
} kvs_array_item_t;

typedef struct kvs_array_s {
	kvs_array_item_t *table;
    int idx;//添加的最后一个
	int total;//总数
} kvs_array_t;


#if ARRAYENGINEENABLE

extern kvs_array_t global_array;

int kvs_array_create(kvs_array_t *inst);
int kvs_array_free(kvs_array_t *inst);

char *kvs_array_get(kvs_array_t *inst, char *key);
int kvs_array_set(kvs_array_t *inst, char *key, char *value);
int kvs_array_mod(kvs_array_t *inst, char *key, char *value);
int kvs_array_del(kvs_array_t *inst, char *key);
int kvs_array_exist(kvs_array_t *inst, char *key);

#elif RBTREEENGINEENABLE

int kvs_rbtree_create();
int kvs_rbtree_free(RBTreeNode **rbtree);

char *kvs_rbtree_get(RBTreeNode *rbtree, char *key);
int kvs_rbtree_set(RBTreeNode **rbtree, char *key, char *value);
int kvs_rbtree_mod(RBTreeNode *rbtree, char *key, char *value);
int kvs_rbtree_del(RBTreeNode **rbtree, char *key);
int kvs_rbtree_exist(RBTreeNode *rbtree, char *key);

extern RBTreeNode *g_rbtree;

#elif SKIPLISTENGINEENABLE
int kvs_skiplist_create();
int kvs_skiplist_free(SkipList *skiplist);

char *kvs_skiplist_get(SkipList *skiplist, char *key);
int kvs_skiplist_set(SkipList *skiplist, char *key, char *value);
int kvs_skiplist_mod(SkipList *skiplist, char *key, char *value);
int kvs_skiplist_del(SkipList *skiplist, char *key);
int kvs_skiplist_exist(SkipList *skiplist, char *key);
void skiplist_print(SkipList *slist);

extern SkipList *g_skipList;

#elif HASHENGINEENABLE

int kvs_hash_create();
int kvs_hash_free(HashTable *table);

char *kvs_hash_get(HashTable *table, char *key);
int kvs_hash_set(HashTable *table, char *key, char *value);
int kvs_hash_mod(HashTable *table, char *key, char *value);
int kvs_hash_del(HashTable *table, char *key);
int kvs_hash_exist(HashTable *table, char *key);

extern HashTable *g_hashTable;

#endif

#endif